﻿using System;
using System.Collections.Generic;
using CfgMusic;
using CSUtils;
using TripleJump;
using U3dGame;
using U3dUtils;
using UI00;
using UnityEngine;
using UnityEngine.UI;
namespace G02.TripleJump.UI {
    /// <summary>
    /// 新手引导界面
    /// </summary>
    public class UI_Help : UIBase {
        const string _tag = "UI_Help.新手引导界面";
        public static string prefabPath;

        protected override string _GetUIPrefabPath() {
            if (prefabPath != null) {
                return prefabPath;
            }
            return "TripleJump/UI/UI_Help/UI_Help.prefab";
        }

        public static Transform parent;

        protected override Transform _GetUIParent() {
            if (parent != null) {
                return parent;
            }
            return UIBase.uiLayer4_uiFront;
        }

        public static void GameStart() {
            if (TripleJumpData.curr.helpStep < 1) {
                CDelayMain.Delay(2).SetEnd("").onCallback = delegate {
                    Open(1);
                };
            }
        }

        static void Open(int step) {
            var paraDic = UIManage.GetNewParaDic();
            paraDic["step"] = step;
            UIManage.Open<UI_Help>(paraDic);
        }

        RectTransform help01, help02;
        Button m_confirmBtn;
        Text m_countDownText;

        protected override void _Init() {
            help01 = m_rootRt.GetControl<RectTransform>("view/help01");
            help02 = m_rootRt.GetControl<RectTransform>("view/help02");
            m_confirmBtn = m_rootRt.GetControl<Button>("view/m_confirmBtn");

            m_confirmBtn.onClick.AddListener(delegate() {
                TripleJumpData.curr.helpStep = currStep;
                CPara.onSetIsHelpStep(false);
                Close();
                CMusicManage.PlayMusic(MusicCfg.button_negative);
            });
            m_countDownText = m_rootRt.GetControl<Text>("view/countDown");
//            countDown0.d_updateStringEvent = delegate(string timeString) {
//                countDown.text = timeString;
//            };
        }

        int currStep;
        CDelayMain countDown0;

        protected override void _Open(Dictionary<string, object> paraDic) {
            //rectTransform.gameObject.SetActive(true);
            //rectTransform.SetSiblingIndex(100);
            currStep = paraDic.GetInt("step");
            CPara.onSetIsHelpStep(true);
            if (currStep == 1) {
                help01.gameObject.SetActive(true);
                help02.gameObject.SetActive(false);
            } else {
                help01.gameObject.SetActive(false);
                help02.gameObject.SetActive(true);
            }
            m_confirmBtn.gameObject.SetActive(false);
            m_countDownText.gameObject.SetActive(true);

            UIDelayShowUtils.SetCountdown(ref countDown0, m_rootRt.gameObject, m_countDownText, delegate {
                m_confirmBtn.gameObject.SetActive(true);
                m_countDownText.gameObject.SetActive(false);
            }, 4);
            //countDown0.SetEnd("");
        }

        public static void SetFlyState(int objId, int flyCount, TripleJump_FristRoleFly.EFlyState flyState, float speedZ) {
            if (flyCount == 3 && flyState == TripleJump_FristRoleFly.EFlyState.e01_startJump) {
                if (TripleJumpData.curr.helpStep < 2) {
                    CDelayMain.Delay(0.5f).SetEnd("").onCallback = delegate {
                        Open(2);
                    };
                }
            }
        }

        public class CPara {
            public static Action<bool> onSetIsHelpStep;
        }
    }
}
